package com.esfak47.mediafetcher.app.controller;

import com.esfak47.common.PageResult;
import com.esfak47.common.Result;
import com.esfak47.mediafetcher.core.domain.Media;
import com.esfak47.mediafetcher.core.service.MediaProvider;
import com.esfak47.mediafetcher.core.service.ProvideQuery;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author tony
 */
@RestController
@Slf4j
public class MediaSearchController {
    @Resource(name = "mediaProvider")
    private
    MediaProvider provider;

    @GetMapping(value = "/media/search")
    public Result<PageResult<Media>> search(@ModelAttribute ProvideQuery query) {
        query.setCrawler(false);
        query.setTimeOutSeconds(30);
        PageResult<Media> provide = provider.provide(query);
        return provide.asResult();
    }

}
